cmake_minimum_required(VERSION 3.10)
project(threads_pool VERSION 1.0.0 DESCRIPTION "A thread pool implementation")

# 设置C标准
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

# 设置输出目录到项目根目录下的 bin 和 lib
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

# 包含目录
include_directories(
    ${PROJECT_SOURCE_DIR}/inc
)

# 创建静态库
add_library(threads_pool STATIC
    ${PROJECT_SOURCE_DIR}/lib/src/threads_pool.c
)

# 设置库文件的输出名称
set_target_properties(threads_pool PROPERTIES OUTPUT_NAME "threads_pool")

# 创建测试可执行文件
add_executable(threads_pool_test
    ${PROJECT_SOURCE_DIR}/test/threads_pool_test.c
)

# 链接测试程序与线程池库
target_link_libraries(threads_pool_test threads_pool)

# 安装规则（可选）
install(TARGETS threads_pool
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin
)

install(FILES ${PROJECT_SOURCE_DIR}/inc/threads_pool.h
    DESTINATION include
)

# 添加测试
enable_testing()
add_test(NAME threads_pool_test
    COMMAND ${PROJECT_SOURCE_DIR}/bin/threads_pool_test
)